package com.bawei.wyg.networkmodel;

import com.bawei.wyg.networkmodel.retrofit.HttpImpl;
import com.bawei.wyg.networkmodel.retrofit.SignRetrofit;
import com.bawei.wyg.networkmodel.retrofit.TokenRetrofit;
import com.bawei.wyg.networkmodel.retrofit.TokenSignRetrofit;
import com.bawei.wyg.networkmodel.retrofit.UpLoadRetrofit;

/**
 * 定义工厂入口
 * */
public class HttpFactory {
    //私有化构造方法
    private HttpFactory(){}
    //单例方法
    private static HttpFactory httpFactory;
    //入口定义
    public static HttpFactory getInstance(){
        if(httpFactory==null){
            httpFactory=new HttpFactory();
        }
        return httpFactory;
    }
    //定义三个产品变量
    private HttpImpl upload,sign,tokenSign,token;
    //返回HttpImpl 类型为HttpType
    public HttpImpl factory(HttpType type){
        //初始
        HttpImpl http=null;
        //switch判断
        //根据不同的类型不同处理
        //空判断为的是不重复创建对象
        switch (type){
            case UPLOADTYPE:
                //当upload为空的时候创建对象
                if(upload==null)
                    //其他操作隐藏 由建造者建造
                    upload=new UpLoadRetrofit.Build().build();
                    http=upload;
                break;
            case SIGNTYPE:
                if(sign==null)
                    sign=new SignRetrofit.Build().build();
                http=sign;
                break;
            case TOKENSIGNTYPE:
                if (tokenSign==null)
                    tokenSign=new TokenSignRetrofit.Build().build();
                http=tokenSign;
                break;
            case TOKEN:
                if (token == null)
                    token = new TokenRetrofit.Build().build();
                http = token;
                break;
        }
        //返回一个http
        return http;
    }
}
